﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    [Serializable]
    public abstract class AbsMetaDataContent : IMetaDataContent, IRefSchema
    {
        #region 接口属性
        
        public virtual string MetaDataID { get; set; }
        public virtual string MetaDataCode { get; set; }
        public virtual string MetaDataName { get; set; }
        public virtual DateTime CreateTime { get; set; }
        public virtual string Creator { get; set; }
        public virtual DateTime LastModifyTime { get; set; }
        public virtual string LastModifier { get; set; }
        public string ProjectBranchID { get; set; }

        [JsonIgnore]
        public IMetaData MetaData { get; set; }

        #endregion

        #region 接口动作、事件
        //public virtual Version CurrentVersion { get; set; }
        //public virtual Version CompatibleMinVersion { get; set; }
        //public virtual Version EngineVersion { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public abstract IRefSchemaEntity BuildRefSchema();
        public abstract object Clone();

        public virtual string GetTopRefSchemaExpr()
        {
            var metaTypeId = this.GetType().Name;
            string abbr = null;
            switch (metaTypeId)
            {
                case nameof(CompositeDataObject):
                    abbr = DataModelConst.CDOAbber;
                    break;
                case nameof(DataObject):
                    var t = this as DataObject;
                    if (t != null && t.IsStatic)
                        abbr = DataModelConst.SDOAbber;
                    else
                        abbr = DataModelConst.DOAbber;
                    break;
                case nameof(DataQuery):
                    abbr = DataModelConst.DQAbber;
                    break;
                case nameof(EntityObject):
                    abbr = DataModelConst.EOAbber;
                    break;
                case nameof(StateMachineMetadata):
                    abbr = DataModelConst.SMAbber;
                    break;
                default:
                    break;
            }

            return $"Schema.{abbr}.{MetaDataCode}";
        }

        #endregion
    }
}
